//
//  MallClassViewController.m
//  CYWFrame
//
//  Created by Macx on 2017/9/9.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "MallClassViewController.h"

//#import "CollectionViewCell.h"
#import "Goods.h"
#import "MallsCollectionViewCell.h"
#import "MallListViewController.h"


static float kLeftTableViewWidth = 80.f;
static float kCollectionViewMargin = 1.f;

@interface MallClassViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, strong) NSMutableArray *collectionDatas;

@end

@implementation MallClassViewController {
    UITableView     *_tableView;
    UICollectionView *_collectionView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self createUI];
    
    [self GETGoodsCates];

}


#pragma mark =========UI==========
- (void)createUI {
    
    self.view.backgroundColor = UISeparatedColorRGB;
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 80.0, SCREEN_HEIGHT)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.tableFooterView = [UIView new];
    _tableView.rowHeight = 55;
    _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    _tableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_tableView];
}


#pragma mark =========代理============

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
        return self.dataSource.count;
//    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //    LeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_Left forIndexPath:indexPath];
    //    CollectionCategoryModel *model = self.dataSource[indexPath.row];
    //    cell.name.text = model.cate_name;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
//    cell.textLabel.text = [NSString stringWithFormat:@"%ld", indexPath.row];
    cell.textLabel.text = self.dataSource[indexPath.row][@"cate_name"];
    cell.textLabel.numberOfLines = 2;
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    cell.textLabel.textColor = UIMainColorRGB;
    
//    UIView *line = [UIView alloc] initWithFrame:<#(CGRect)#>
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

#pragma mark =========响应============

// 商品分类
- (void)GETGoodsCates {
    
[[NetworkTool sharedTool] requestWithName:@"获取商品分类" URLString:APIMallsGoodsCates parameters:nil method:@"GET" callBack:^(id responseObject) {
    /*
    self.dataSource = responseObject[@"data"];
	NSArray *categories = responseObject[@"data"];
	for (NSDictionary *dict in categories)
	{
		CollectionCategoryModel *model = [[CollectionCategoryModel alloc] init];
		[model setValuesForKeysWithDictionary:dict];
		[self.dataSource addObject:model];

		NSMutableArray *datas = [NSMutableArray array];
		for (NSDictionary *d in model.children) {
			SubCategoryModel *m = [[SubCategoryModel alloc] init];
			[m setValuesForKeysWithDictionary:d];
			[datas addObject:m];
		}
		[self.collectionDatas addObject:datas];
	}

	[self.tableView reloadData];
	[self.collectionView reloadData];

	[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
								animated:YES
						  scrollPosition:UITableViewScrollPositionNone];
	*/
    }];
    
}
     
     
     // 懒加载
#pragma mark - Getters
 - (NSMutableArray *)dataSource
{
    if (!_dataSource)
    {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}
 
 - (NSMutableArray *)collectionDatas
{
    if (!_collectionDatas)
    {
        _collectionDatas = [NSMutableArray array];
    }
    return _collectionDatas;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
